package model.cell;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import model.interfaces.IDrawable;

/**
 * Base class for cells.
 * It implements methods to retrieve position and dimension of the cell. 
 * 
 * @author alexandre.altun
 */
public abstract class AbstractCell implements IDrawable, Cloneable {
	
	protected Rectangle _rect ;
	protected Color color;
	
	
	public AbstractCell(Point pos, Dimension dim){
		_rect = new Rectangle(pos,dim);
	}

	public abstract void draw(Graphics g) ;
	
	public Rectangle getRectangle() {
		return (Rectangle) _rect.clone();
	}
	
	public void setRectangle(Rectangle newRect) {
		_rect = newRect;
	}
	
	public int getGridPosX() {
		assert(_rect.width > 0);
		return (int) (_rect.x / _rect.width);			
	}
	
	public int getGridPosY() {
		assert(_rect.height > 0);
		return (int) (_rect.y / _rect.height);			
	}
	
	public Object clone() {
		Object o = null;
		try {
			o = super.clone();
		} catch(CloneNotSupportedException cnse) {
			cnse.printStackTrace(System.err);
		}
		
		return o;
	}
}
